#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
	{                                         \
		cerr << "\033[32;1m" << #x << " -> "; \
		err(x);                               \
	}
void err()
{
	cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
	cerr << a << ' ';
	err(x...);
}
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 3e5 + 50;

#define int long long

struct edge
{
	int to, cap, rev;
	edge(int to = 0, int cap = 0, int rev = 0)
		: to(to), cap(cap), rev(rev)
	{
	}
};

vector<edge> G[N];
int n;

void addEdge(int u, int v, int w1, int w2)
{
	G[u].emplace_back(v, w1, G[v].size());
	G[v].emplace_back(u, w2, G[u].size() - 1);
}

// edge f[N];
int feid[N];
int fson[N], ffa[N];
int tson[N], ans[N];

bool notLeaf[N];

inline int getRev(int u, int eid)
{
	int v = G[u][eid].to, reid = G[u][eid].rev;
	return G[v][reid].cap;
}

void dfs(int u, int fa)
{
	int sz = G[u].size();
	fson[u] = 0;
	for (int i = 0; i < sz; ++i)
	{
		const auto &e = G[u][i];
		if (e.to == fa)
		{
			feid[u] = i;
			continue;
		}
		notLeaf[u] = true;
		dfs(e.to, u);
		tson[e.to] = min(fson[e.to], getRev(u, i));
		fson[u] += tson[e.to];
	}

	if (!notLeaf[u])
	{
		fson[u] = 100000;
	}
}

void dfs2(int u, int fa)
{
	if (u != fa) 
	{
		ffa[u] = min(getRev(u, feid[u]), ans[fa] - tson[u]);
		if (fa == 1 && G[1].size() == 1)
		{
			ffa[u] = getRev(u, feid[u]);
		}
	}
	else
		ffa[u] = 0;
	ans[u] = ffa[u];
	if (notLeaf[u])
		ans[u] += fson[u];
	for (const auto e : G[u])
	{
		if (e.to == fa)
			continue;
		dfs2(e.to, u);
	}
}

signed main()
{
	scanf("%lld", &n);
	for (int i = 0; i < n - 1; ++i)
	{
		int u, v, w1, w2;
		scanf("%lld%lld%lld%lld", &u, &v, &w1, &w2);
		addEdge(u, v, w1, w2);
	}
	dfs(1, 1);
	dfs2(1, 1);
	for (int i = 1; i <= n; ++i)
		printf("%lld\n", ans[i]);

	// for (int i=1; i<=n; ++i)
	// 	dbg(i, fson[i], tson[i], ffa[i], ans[i]);

	return 0;
}